const baseUrl: string = "http://back.aabbcc.icu";
import { RequestConfig, RequestSuccessCallbackResult } from "@/types/request";

export const request = <T>(config: RequestConfig) =>
  new Promise<T>((resolve, reject) =>
    uni.request({
      url: baseUrl + config.url,
      method: config.method || "GET",
      data: Object.assign((config.data as object) ?? {}, {
        cookie: uni.getStorageSync("cookie"),
        // timestamp: Date.now(),
      }),
      success: (res: RequestSuccessCallbackResult) => {
        resolve(res.data as T);
      },
      fail: (error) => {
        uni.showToast({
          icon: "none",
          title: "系统异常，请稍后重试！",
        });
        reject(error);
      },
    })
  );
